package com.tjsinfo.tjsoa.system.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.json.JSONArray;
import org.json.JSONObject;

import com.tjsinfo.tjsoa.system.bo.IDepartmentBo;
import com.tjsinfo.tjsoa.system.vo.TSystemDepartment;

/**
 * 部门查询列表
 * @author wangxiaowei
 *
 */
public class DepartmentListAction extends Action{
	private IDepartmentBo departmentBo;
	
	public IDepartmentBo getDepartmentBo() {
		return departmentBo;
	}

	public void setDepartmentBo(IDepartmentBo departmentBo) {
		this.departmentBo = departmentBo;
	}

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		List<TSystemDepartment> list;
		JSONArray array = new JSONArray();
		JSONObject object = new JSONObject();
		if (request.getParameter("start") == null) {
			list = departmentBo.selectSystemDepartment(0, 10);
		} else {
			Integer first = Integer.parseInt(request.getParameter("start"));
			list = departmentBo.selectSystemDepartment(first, 10);
		}
		Integer totalProperty = departmentBo.SelectSystemDepartmentTotalLine();
		object.put("totalProperty", totalProperty);
		for (TSystemDepartment systemDepartment : list) {
			if (systemDepartment.getIsDel() == 1) {
				systemDepartment.setStart("禁用");
			} else {
				systemDepartment.setStart("启用");	
			}
			JSONObject systemdepartmentJSON = new JSONObject(systemDepartment);
			array.put(systemdepartmentJSON);
		}
		object.put("root", array);
		response.getWriter().print(object);
		return null;
	}
	
}	
